;(in-package 'user)

(defun test-sentence (item)
  (let* ((s (first item))
	 (expected (second item))
	 current)
    (format t "~%~%SENTENCE: ~a" s)
    (parse-list (append s '($)))
    (if *parse-value*
	(dolist (fs *parse-value*)
		(pns fs)(terpri))
      (print NIL))
    (setq current *parse-value*)
    (cond ((every #'(lambda (fs)
		       (find fs current :test #'unify))
		   expected)
	    (format t "~%Test Passed!")
	   t)
	  (t
	    (format t "~%Test failed: ~s" s)
	    (format t "~%Expected: ~s" expected)
	    nil))))

(defun run-tests ()
  (let ((failures 0))
    (dolist (item *tests*)
	    (unless (test-sentence item)
		    (incf failures)))
    (format t "~%~a failures." failures)))

(defun generate-tests (list)
  (princ "(SETQ *TESTS* '(")
  (dolist (x list)
	  (parse-list (append x '($)))
	  (if *parse-value*
	      (pns (list x *parse-value*))
	    (format t "~%~s" (list x *parse-value*))))
  (princ "))")
  nil
)

(defvar *sentences*)

(setq *sentences* 
      '(
	(a boy)
	(a boys)
	(the boy)
	(the boys)
	(the man)
	(the men)
	(the man sees)
	(the man see)
	(the men see)
	(the men sees)
	(the man sees the boy)
	(the man sees the boys)
	(the men see the boys with the telescope)
	(the man sees the boy with the dog)
))

(defvar *tests*)

(SETQ *TESTS* '(
((A BOY)
 (((CAT N) (NUMBER SG) (PERSON 3) (ROOT "boy") (SEM *O-BOY-1)
   (DET
      ((NUMBER SG) (CAT DET) (ROOT "a") (REFERENCE INDEFINITE))))))
((A BOYS) NIL)
((THE BOY)
 (((CAT N) (NUMBER SG) (PERSON 3) (ROOT "boy") (SEM *O-BOY-1)
   (DET
      ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))
((THE BOYS)
 (((CAT N) (NUMBER PL) (PERSON 3) (ROOT "boy") (SEM *O-BOY-1)
   (DET
      ((NUMBER PL) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))
((THE MAN)
 (((CAT N) (NUMBER SG) (PERSON 3) (ROOT "man") (SEM *O-MAN-1)
   (DET
      ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))
((THE MEN)
 (((CAT N) (PERSON 3) (ROOT "men") (NUMBER PL) (SEM *O-MAN-1)
   (DET
      ((NUMBER PL) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))
((THE MAN SEES)
 (((MOOD DECLARATIVE) (NUMBER SG) (PERSON 3) (VALENCY INTRANS)
   (CAT V) (ROOT "see") (SEM *A-SEE-2)
   (SUBJ
      ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "man") (SEM *O-MAN-1)
       (DET
          ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))))
((THE MAN SEE) NIL)
((THE MEN SEE)
 (((MOOD DECLARATIVE) (NUMBER PL) (PERSON 3) (VALENCY INTRANS)
   (CAT V) (ROOT "see") (SEM *A-SEE-2)
   (SUBJ
      ((CAT N) (PERSON 3) (ROOT "men") (NUMBER PL) (SEM *O-MAN-1)
       (DET
          ((NUMBER PL) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))))
((THE MEN SEES) NIL)
((THE MAN SEES THE BOY)
 (((MOOD DECLARATIVE) (NUMBER SG) (PERSON 3) (VALENCY TRANS)
   (CAT V) (ROOT "see") (SEM *A-SEE-1)
   (SUBJ
      ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "man") (SEM *O-MAN-1)
       (DET
          ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE)))))
   (OBJ
      ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "boy") (SEM *O-BOY-1)
       (DET
          ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))))
((THE MAN SEES THE BOYS)
 (((MOOD DECLARATIVE) (NUMBER SG) (PERSON 3) (VALENCY TRANS)
   (CAT V) (ROOT "see") (SEM *A-SEE-1)
   (SUBJ
      ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "man") (SEM *O-MAN-1)
       (DET
          ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE)))))
   (OBJ
      ((CAT N) (NUMBER PL) (PERSON 3) (ROOT "boy") (SEM *O-BOY-1)
       (DET
          ((NUMBER PL) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))))
; ** ATTACH FAILED (*O-BOY-1 (+INSTRUMENT *O-TELESCOPE-1))
; ** ATTACH FAILED (*O-BOY-1 (+ACCOMPLICE *O-TELESCOPE-1))
; ** ATTACHING (*A-SEE-1 (+INSTRUMENT *O-TELESCOPE-1))
; ** ATTACH FAILED (*A-SEE-1 (+ACCOMPLICE *O-TELESCOPE-1))
((THE MEN SEE THE BOYS WITH THE TELESCOPE)
 (((MOOD DECLARATIVE) (NUMBER PL) (PERSON 3) (VALENCY TRANS)
   (CAT V) (ROOT "see") (SEM *A-SEE-1)
   (SUBJ
      ((CAT N) (PERSON 3) (ROOT "men") (NUMBER PL) (SEM *O-MAN-1)
       (DET
          ((NUMBER PL) (CAT DET) (ROOT "the") (REFERENCE DEFINITE)))))
   (OBJ
      ((CAT N) (NUMBER PL) (PERSON 3) (ROOT "boy") (SEM *O-BOY-1)
       (DET
          ((NUMBER PL) (CAT DET) (ROOT "the") (REFERENCE DEFINITE)))))
   (PPADJUNCT
      ((CAT P) (ROOT "with") (SEMROLE +INSTRUMENT)
       (OBJ
          ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "telescope")
           (SEM *O-TELESCOPE-1)
           (DET
              ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))))))
; ** ATTACH FAILED (*O-BOY-1 (+INSTRUMENT *O-DOG-1))
; ** ATTACHING (*O-BOY-1 (+ACCOMPLICE *O-DOG-1))
; ** ATTACH FAILED (*A-SEE-1 (+INSTRUMENT *O-DOG-1))
; ** ATTACH FAILED (*A-SEE-1 (+ACCOMPLICE *O-DOG-1))
((THE MAN SEES THE BOY WITH THE DOG)
 (((MOOD DECLARATIVE) (NUMBER SG) (PERSON 3) (VALENCY TRANS)
   (CAT V) (ROOT "see") (SEM *A-SEE-1)
   (SUBJ
      ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "man") (SEM *O-MAN-1)
       (DET
          ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE)))))
   (OBJ
      ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "boy") (SEM *O-BOY-1)
       (DET
          ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE)))
       (PPADJUNCT
          ((CAT P) (ROOT "with") (SEMROLE +ACCOMPLICE)
           (OBJ
              ((CAT N) (NUMBER SG) (PERSON 3) (ROOT "dog")
               (SEM *O-DOG-1)
               (DET
                  ((NUMBER SG) (CAT DET) (ROOT "the") (REFERENCE DEFINITE))))))))))))))